<template>
    <div id="templateDiv">
        <Spin size="large" fix v-if="ExportLoading"></Spin>
        <Row class="button_row">
                <span style="float: left;">
                 <Button type="primary" style="" @click="handleAdd">上报月度设置</Button>
                    <Button type="primary" class="button_item_left" @click="generation">数据生成</Button>
                    <Button type="primary" class="button_item_left" @click="check">数据查验</Button>
                    <Button type="primary" class="button_item_left" @click="exportExcelNew(1)">家庭信息导出</Button>
                    <Button type="primary" class="button_item_left" @click="exportExcelNew(2)">人员信息导出</Button>
                </span>
        </Row>
        <div class="table_div">
            <vxe-table border
                       resizable
                       row-id="id"
                       :row-key="true"
                       show-overflow="tooltip"
                       align="center"
                       header-align="center"
                       ref="xTree"
                       :loading="Loading"
                       :radio-config="{highlight: true}"
                       @cell-click="selectChange"
                       :data="tableData">
                <vxe-table-column type="radio" width="60" align="center"/>
                <vxe-table-column field="prnt0001" title="数据月度" align="center"/>
                <vxe-table-column field="prnt0002" title="本月总户数" align="center"/>
                <vxe-table-column field="prnt0003" title="本月总人数" align="center"/>
                <vxe-table-column field="prnt0004" title="本月总保障金额" align="center"/>
                <vxe-table-column field="prnt0005" title="是否生成" align="center" :formatter="renderPrnt0005"/>
            </vxe-table>
            <Page :total="dataCount" :page-size="pageSize" show-total class="paging"
                  @on-change="handleTableChange" :current="pageNo"></Page>
        </div>
        <ls-report-add-modal ref="modalForm" @ok="modalFormOk"/>
        <check-result-modal ref="checkResultModal"/>
    </div>
</template>

<script>
    import {postAction} from '@/api/request'
    import {CommonMixin} from '@/views/common/js/CommonMixin'
    import LsReportAddModal from './modules/LsReportAddModal'
    import checkResultModal from './checkResultList'

    export default {
        mixins: [CommonMixin],
        components: {LsReportAddModal, checkResultModal},
        data() {
            return {
                selectedData: {},
                Loading: false,
                queryParam: {},
                url: {
                    list: "/api/ac/subsistence/ss00028Service/getPageList",
                    generation: "/api/ac/subsistence/ss00028Service/insertGeneration",
                    checkCurrent: "/api/ac/subsistence/ss00028Service/updateCheckCurrent",
                    exportFamily: "/api/ac/subsistence/ss00028Service/exportFamily",
                    exportPeople: "/api/ac/subsistence/ss00028Service/exportPeople",
                    exportExcel: "",
                },
                ExportLoading: false,
                exportFileName: "",
            }
        },
        methods: {
            selectChange({row}) {
                this.$refs.xTree.setRadioRow(row);
                this.selectedData = row;
            },
            generation() {
                if (!this.selectedData || !this.selectedData.id) {
                    this.$Message.error("请选择需要生成数据！");
                    return;
                }
                this.ExportLoading = true;
                var id = this.selectedData.id;
                var prnt0001 = this.selectedData.prnt0001;
                postAction(this.url.generation, {id: id, prnt0001: prnt0001}).then((res) => {
                    if (res.data.errcode != 0) {
                        this.$Message.error(res.data.errmsg);
                    } else {
                        this.$Message.success("生成成功！");
                        this.selectedData = {};
                        this.loadData();
                    }
                }).finally(() => {
                    this.ExportLoading = false;
                });
            },
            renderPrnt0005(h) {
                if (h.cellValue == '1') {
                    return "已生成 ";
                } else {
                    return "未生成 ";
                }
            },
            check() {
                if (!this.selectedData || !this.selectedData.id) {
                    this.$Message.error("请选择需要生成数据！");
                    return;
                }
                if (this.selectedData.prnt0005 != '1') {
                    this.$Message.error("请先生成数据！");
                    return;
                }
                this.ExportLoading = true;
                postAction(this.url.checkCurrent, {}).then((res) => {
                    if (res.data.errcode != 0) {
                        this.$Message.error(res.data.errmsg);
                    } else {
                        this.$refs.checkResultModal.loadResult("", 'ls', 'current');
                    }
                }).finally(() => {
                    this.ExportLoading = false;
                });
            },
            exportExcelNew(type) {
                if (!this.selectedData || !this.selectedData.id) {
                    this.$Message.error("请选择需要生成数据！");
                    return;
                }
                if (this.selectedData.prnt0005 != '1') {
                    this.$Message.error("请先生成数据！");
                    return;
                }
                if (type == 1) {
                    this.url.exportExcel = this.url.exportFamily;
                    this.exportFileName = "临时救助家庭数据上报";
                } else if (type == 2) {
                    this.url.exportExcel = this.url.exportPeople;
                    this.exportFileName = "临时救助成员数据上报";
                } else {
                    this.url.exportExcel = "";
                    this.exportFileName = "";
                }
                this.exportExcel();
            }

        },
        created() {
            this.loadData();
        },

    }
</script>
<style scoped>


</style>
